/*
 * @Description: 日志存储 二次封装
 * @Author: zhihong deng
 * @Date: 2021-08-22 13:00:51
 * @LastEditors: zhihong deng
 * @LastEditTime: 2021-08-22 13:46:37
 */
const log4js = require('log4js')
const levels = {
  'trace':log4js.levels.TRACE,
  'debug':log4js.levels.DEBUG,
  'info':log4js.levels.INFO,
  'warn':log4js.levels.WARN,
  'error':log4js.levels.ERROR,
  'fatal':log4js.levels.FATAL,
}
log4js.configure({
  appenders:{
    console:{type:'console'},
    info:{
      type:'file',
      filename:'logs/all-logs.log'
    },
    error:{
      type:'dateFile',
      filename:'logs/log',
      alwaysIncludePattern:true//设置文件名称为 filename + pattern
    }
  },
  categories:{
    default:{appenders:['console'],level:'debug'},
    info:{
      appenders:['console'],
      level:'info'
    },
    error:{
      appenders:['error','console'],
      level:'error'
    }
  }
})
/**
 * @description: 日志输出，level为debug
 * @param {string} content
 * @return {*}
 */
exports.debug = (content)=>{
  let logger = log4js.getLogger();
  logger.level = levels.debug;
  logger.debug(content)
}
/**
 * @description: 日志输出，level为info
 * @param {string} content
 * @return {*}
 */
 exports.info = (content)=>{
  let logger = log4js.getLogger('info');
  logger.level = levels.info;
  logger.info(content)
}
/**
 * @description: 日志输出，level为error
 * @param {string} content
 * @return {*}
 */
 exports.error = (content)=>{
  let logger = log4js.getLogger('error');
  logger.level = levels.error;
  logger.error(content)
}